package com.xiaobai.java_core.copy;

import java.io.Serializable;

/**
 * @Author 王天文
 * @Date 2025/1/5 15:54
 * @Description:
 */
public class Person implements Serializable, Cloneable {

    private static final long serialVersionUID = 7973985896659216593L;

    public Person() {
    }

    public Person(String name, String sex, Address address) {
        this.name = name;
        this.sex = sex;
        this.address = address;
    }

    private String name;

    private String sex;

    private Address address;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    /**
     * 浅拷贝
     * @return
     * @throws CloneNotSupportedException
     */
    @Override
    protected Person clone() throws CloneNotSupportedException {
        Person personClone = (Person) super.clone();
        return personClone;
    }

    /**
     * 深拷贝
     * @return
     * @throws CloneNotSupportedException
     */
    public Person deepClone() throws CloneNotSupportedException {
        Person personClone = (Person) super.clone();
        personClone.address = this.address.clone();
        return personClone;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", address=" + address +
                '}';
    }
}
